package com.xinhua.erp.controller;

import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.pojo.Supplier;
import com.xinhua.erp.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@RestController
@RequestMapping("supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;


    @GetMapping("{id}")
    public Result findById(@PathVariable long id){
        System.out.println(id);
        return supplierService.findById(id);
    }

    @GetMapping("{type}/{page}/{size}")
    public Result findByType(@PathVariable String type,@PathVariable int page,@PathVariable int size){
        return supplierService.findSupplierByType(type,page,size);
    }

   /* @GetMapping("{page}/{size}")
    public Result findAll(@PathVariable int page,@PathVariable int size){
        return supplierService.findAll(page,size);
    }*/

    @GetMapping("type/{type}")
    public Result findAll(@PathVariable String type){
        return supplierService.findAllByType(type);
    }

    @DeleteMapping("{id}")
    public  Result deleteById(@PathVariable long id){
        return supplierService.deleteById(id);
    }

    @PostMapping
    public Result save(@RequestBody Supplier supplier){
        return supplierService.save(supplier);
    }

    @PutMapping("{id}")
    public Result update(@PathVariable Long id,@RequestBody Supplier supplier){
        return supplierService.update(id,supplier);
    }
    @PutMapping("get/{id}/{amount}")
    public Result updateAllneedget(@PathVariable Long id, @PathVariable double amount){
        BigDecimal bigDecimal = new BigDecimal(amount);
        return supplierService.updateAllneedget(id,bigDecimal);
    }
    @PutMapping("pay/{id}/{amount}")
    public Result updateAllneedpay(@PathVariable Long id,@PathVariable double amount){
        BigDecimal bigDecimal = new BigDecimal(amount);
        return supplierService.updateAllneedpay(id,bigDecimal);
    }

    @PostMapping("search/{page}/{size}")
    public Result Search(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size){
        return supplierService.Search(searchMap,page,size);
    }
}
